# Maintainer: Justin Kromlinger <hashworks@archlinux.org>

pkgname=opensearch-performance-analyzer-plugin
pkgver=2.6.0.0
pkgrel=1
_opensearchver=2.6.0
_jdkver=11
_rcaver="$(echo -n "${_opensearchver}" | sed 's/\.[0-9]\+$//')"
pkgdesc="OpenSearch Performance Analyzer Plugin"
arch=('loong64' 'x86_64')
url="https://opensearch.org/docs/latest/monitoring-plugins/pa"
license=('Apache')
depends=("opensearch=${_opensearchver}")
makedepends=("java-environment=${_jdkver}" 'unzip' 'git')
source=(
  "${pkgname}-${pkgver}.tar.gz::https://github.com/opensearch-project/performance-analyzer/archive/${pkgver}.tar.gz"
  "git+https://github.com/opensearch-project/performance-analyzer-rca.git#branch=${_rcaver}"
)
sha256sums=('b4a33a637e40d81d640bcc8e6a82db1419d78b0a599e28505ddaacfb12be0680'
            'SKIP')

build() {
  cd "performance-analyzer-${pkgver}"
  export JAVA_HOME="/usr/lib/jvm/java-${_jdkver}-openjdk"
  export PATH="/usr/lib/jvm/java-${_jdkver}-openjdk/bin:$PATH"
  export GRADLE_OPTS="-Dbuild.snapshot=false -Dopensearch.version=${_opensearchver}"
  # integTest (Reaper) requires JDK 14
  ./gradlew assemble \
    -Dperformance-analyzer-rca.build=true \
    -Dperformance-analyzer-rca.branch=2.3 \
    --exclude-task ":integTest" \
    --exclude-task ":jacocoTestReport" \
    --exclude-task ":updateShas"
}

package() {
  install -dm755 "${pkgdir}/usr/share/opensearch/plugins/opensearch-performance-analyzer"
  cd "${pkgdir}/usr/share/opensearch/plugins/opensearch-performance-analyzer"
  unzip "${srcdir}/performance-analyzer-${pkgver}/build/distributions/opensearch-performance-analyzer-${pkgver}.zip"

  install -Dm644 "${srcdir}/performance-analyzer-${pkgver}/LICENSE.txt" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE.txt"
}
